/* Hao Hua He, SN: 020920435 */
/* Denys Silin, SN: 042080358 */

#include <stdio.h>
#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#include <Xm/BulletinB.h>
#include <Xm/Label.h>
#include <Xm/Text.h>
#include <Xm/PushB.h>
#include <Xm/ToggleB.h>
#include <string.h>
#include <Xm/TextF.h>
#include <Xm/Form.h>
#include <Xm/ToggleBG.h>
#include <Xm/RowColumn.h>
#include "server.h"

XtAppContext context;
Widget toplevel, manager,
label1, text1,
label2, text2,
label3, text3,
label4, text4,
label5, text5,
label6, text6,
label7, text7,
search_in, cancel, dialog, shell,
pl1, pl2, pl3, pl4, pl5, pl6, pl7,
pt1, pt2, pt3, pt4, pt5, pt6, pt7,
create, forward, backward, search, quit,
radio_box, radio1, radio2, radio3,
radio_box2, radio4, radio5, radio6,
text_w, textl, popup, ok, text_wp, pane,
main_w, rc, sw, drawing_a, option_menu, pb,
result;
XmRendition rendition;
int index = 0;

/*
Display *display;
XFontStruct *myfont;
String fontname = "-*-Helvetica-I-R-*--*-240-*-*-*-*-ISO8859-1";
*/
Arg	arglist[10];
int	i, r1,r2,r3,r4,r5,r6;
int toggle_item_set;
char *value;
char *t1;
char *t2;
char *t3;
char *t5;
char *t6;
char *t;

void Quit(Widget w, XtPointer client_data, XtPointer call_data)
{ 
	db_close();
	exit(0); 
}
void Close(Widget w, XtPointer client_data, XtPointer call_data)
{ 
	XtDestroyWidget(dialog);
}



void add_result (Widget text_w, XtPointer client_data,
				 XtPointer call_data)
{
	ARecord current;
	char temp1[100];
	char temp2[50];
	/*
	strcpy(t1, XmTextFieldGetString (text1));
	strcpy(t2, XmTextFieldGetString (text2));
	strcpy(t3, XmTextFieldGetString (text3));
	strcpy(t5, XmTextFieldGetString (text5));
	strcpy(t6, XmTextFieldGetString (text6));
*/
strcpy(temp2, XmTextFieldGetString (text6));
chomp(temp2);
	
	
	current.date=(char*)malloc(strlen(XmTextFieldGetString (text1)));
	strcpy(current.date,XmTextFieldGetString (text1));
	current.requestor=(char*)malloc(strlen(XmTextFieldGetString (text2)));
	strcpy(current.requestor,XmTextFieldGetString (text2));
	current.email=(char*)malloc(strlen(XmTextFieldGetString (text3)));
	strcpy(current.email,XmTextFieldGetString (text3));

	if(r1)
	{
		current.priority=(char*)malloc(strlen("High"));

		strcpy(current.priority, "High");
	}
	else if(r2)
	{
		current.priority=(char*)malloc(strlen("Medium"));

		strcpy(current.priority, "Medium");
	}
	else
	{
		current.priority=(char*)malloc(strlen("Low"));

		strcpy(current.priority, "Low");
	}
	current.needed=(char*)malloc(strlen(XmTextFieldGetString (text5)));
	strcpy(current.needed,XmTextFieldGetString (text5));
	if(r4)
	{
		current.status=(char*)malloc(strlen("Open"));

		strcpy(current.status,"Open");
	}
	else if(r5)
	{
		strcpy(temp1, "Awaiting ");
		strcat(temp1, temp2); 
		current.status=(char*)malloc(strlen(temp1));
		strcpy(current.status,temp1);
	}
	else
	{
		current.status=(char*)malloc(strlen("Done"));		
		strcpy(current.status,"Done");
	}

	if (t = XmTextGetString (textl)) {
		/* manipulate text in whatever way is necessary */

		strcpy(t, XmTextGetString (textl));
		current.description=(char*)malloc(strlen(t));
		strcpy(current.description,t);
		chomp(current.description);
		printf("%s\n", temp1);
		printf("date: %s!\n", current.date);
		printf("requestor: %s!\n", current.requestor);
		printf("email: %s!\n", current.email);
		printf("priority: %s!\n", current.priority);
		printf("needed: %s!\n", current.needed);
		printf("status: %s!\n", current.status);
		printf("description: %s!\n", current.description);
		/* free text or there will be a memory leak */
		XtFree (t);
	db_add_record(current,1); 
	}

}

void option_cb (Widget menu_item, XtPointer client_data,
				XtPointer call_data)
{
	int item_no = (int) client_data;
	puts (XtName (menu_item));
}

void forw (Widget pb, XtPointer client_data, XtPointer call_data)
{
char       text[5000];
	int        max;
	ARecord returned;

	/****************************INSERT FUNCTION HERE******************************/

	db_open();
	max = db_getsize();
	index++;
	if(index>max-1)
	index=max-1;

		chomp(dbase.data[index].date);
		chomp(dbase.data[index].requestor);
		chomp(dbase.data[index].email);
		chomp(dbase.data[index].priority);
		chomp(dbase.data[index].needed);
		chomp(dbase.data[index].status);

		XmTextSetString (pt1, dbase.data[index].date);
		XmTextSetString (pt2, dbase.data[index].requestor);
		XmTextSetString (pt3, dbase.data[index].email);
		XmTextSetString (pt4, dbase.data[index].priority);
		XmTextSetString (pt5, dbase.data[index].needed);
		XmTextSetString (pt6, dbase.data[index].status);
		XmTextSetString (text_wp, dbase.data[index].description); 
printf("index = %d\n", index);
	/****************************INSERT FUNCTION HERE******************************/

	XtFree (text); /* must free text gotten from XmStringUnparse() */

}
void backw (Widget pb, XtPointer client_data, XtPointer call_data)
{
char       text[5000];
	int        max;
	ARecord returned;

	/****************************INSERT FUNCTION HERE******************************/

	db_open();
	max = db_getsize();
	index--;
	if(index<0)
	index=0;

		chomp(dbase.data[index].date);
		chomp(dbase.data[index].requestor);
		chomp(dbase.data[index].email);
		chomp(dbase.data[index].priority);
		chomp(dbase.data[index].needed);
		chomp(dbase.data[index].status);

		XmTextSetString (pt1, dbase.data[index].date);
		XmTextSetString (pt2, dbase.data[index].requestor);
		XmTextSetString (pt3, dbase.data[index].email);
		XmTextSetString (pt4, dbase.data[index].priority);
		XmTextSetString (pt5, dbase.data[index].needed);
		XmTextSetString (pt6, dbase.data[index].status);
		XmTextSetString (text_wp, dbase.data[index].description); 
printf("index = %d\n", index);
	/****************************INSERT FUNCTION HERE******************************/

	XtFree (text); /* must free text gotten from XmStringUnparse() */
}

void pushed (Widget pb, XtPointer client_data, XtPointer call_data)
{
	XmString     t, btn1, btn2;

	void         read_name(Widget, XtPointer, XtPointer);
	void         toggle_callback(Widget, XtPointer, XtPointer);
	void         destroy_callback(Widget, XtPointer, XtPointer);
	Arg          args[5];
	int          n = 0;
	
		db_open();
	t = XmStringCreateLocalized ("Enter Search Key:");
	XtSetArg (args[n], XmNselectionLabelString, t); n++;
	XtSetArg (args[n], XmNuserData, 0); n++;

	dialog = XmCreateDialogShell(pb, "Search", args, n);
	XmStringFree (t); 

	n=0;
	XtSetArg (args[n], XmNheight, 550); n++;
	XtSetArg (args[n], XmNwidth, 600); n++;
	shell = XtCreateManagedWidget("shell", xmBulletinBoardWidgetClass, dialog, args, n);
	XtManageChild (shell);	
/* Search */
	n=0;
	XtSetArg(args[n], XmNx, 10); n++;
	XtSetArg(args[n], XmNy, 10); n++;
	XtSetArg(args[n], XmNvalue,
		"Type text here"); n++;
	search_in = XmCreateTextField (dialog, "search_in", args, n);
	XtManageChild (search_in);
/* Output */	
	n = 0;
	XtSetArg(args[n], XmNx,10); n++;
	XtSetArg(args[n], XmNy, 40); n++;
	pl1 = XtCreateWidget ("Date:", xmLabelWidgetClass, dialog, args, n);
	XtManageChild (pl1);
	n=0;
	XtSetArg(args[n], XmNx,100); n++;
	XtSetArg(args[n], XmNy, 40); n++;
	XtSetArg (args[n], XmNeditable, False);  n++;   
	XtSetArg (args[n], XmNcursorPositionVisible, False); n++;	
	pt1 = XmCreateTextField (dialog, "pt1", args, n);
	XtManageChild (pt1);
	n = 0;
	XtSetArg(args[n], XmNx,10); n++;
	XtSetArg(args[n], XmNy, 70); n++;
	pl2 = XtCreateWidget ("Requestor:", xmLabelWidgetClass, dialog, args, n);
	XtManageChild (pl2);
	n=0;
	XtSetArg(args[n], XmNx,100); n++;
	XtSetArg(args[n], XmNy, 70); n++;
	XtSetArg (args[n], XmNeditable, False);  n++;   
	XtSetArg (args[n], XmNcursorPositionVisible, False); n++;	
	pt2 = XmCreateTextField (dialog, "pt2", args, n);
	XtManageChild (pt2);
	n = 0;
	XtSetArg(args[n], XmNx,10); n++;
	XtSetArg(args[n], XmNy, 100); n++;
	pl3 = XtCreateWidget ("Email:", xmLabelWidgetClass, dialog, args, n);
	XtManageChild (pl3);
	n=0;
	XtSetArg(args[n], XmNx,100); n++;
	XtSetArg(args[n], XmNy, 100); n++;
	XtSetArg (args[n], XmNeditable, False);  n++;   
	XtSetArg (args[n], XmNcursorPositionVisible, False); n++;	
	pt3 = XmCreateTextField (dialog, "pt3", args, n);
	XtManageChild (pt3);
	n = 0;
	XtSetArg(args[n], XmNx,10); n++;
	XtSetArg(args[n], XmNy, 130); n++;
	pl4 = XtCreateWidget ("Priority:", xmLabelWidgetClass, dialog, args, n);
	XtManageChild (pl4);
	n=0;
	XtSetArg(args[n], XmNx,100); n++;
	XtSetArg(args[n], XmNy, 130); n++;
	XtSetArg (args[n], XmNeditable, False);  n++;   
	XtSetArg (args[n], XmNcursorPositionVisible, False); n++;	
	pt4 = XmCreateTextField (dialog, "pt4", args, n);
	XtManageChild (pt4);
	n = 0;
	XtSetArg(args[n], XmNx,10); n++;
	XtSetArg(args[n], XmNy, 160); n++;
	pl5 = XtCreateWidget ("Needed:", xmLabelWidgetClass, dialog, args, n);
	XtManageChild (pl5);
	n=0;
	XtSetArg(args[n], XmNx,100); n++;
	XtSetArg(args[n], XmNy, 160); n++;
	XtSetArg (args[n], XmNeditable, False);  n++;   
	XtSetArg (args[n], XmNcursorPositionVisible, False); n++;	
	pt5 = XmCreateTextField (dialog, "pt5", args, n);
	XtManageChild (pt5);	
	n = 0;
	XtSetArg(args[n], XmNx,10); n++;
	XtSetArg(args[n], XmNy, 190); n++;
	pl6 = XtCreateWidget ("Status:", xmLabelWidgetClass, dialog, args, n);
	XtManageChild (pl6);
	n=0;
	XtSetArg(args[n], XmNx,100); n++;
	XtSetArg(args[n], XmNy, 190); n++;
	XtSetArg (args[n], XmNeditable, False);  n++;   
	XtSetArg (args[n], XmNcursorPositionVisible, False); n++;	
	pt6 = XmCreateTextField (dialog, "pt6", args, n);
	XtManageChild (pt6);
	
		XtSetArg(arglist[i], XmNx, 100); i++;
	XtSetArg(arglist[i], XmNy, 310); i++;
	XtSetArg(arglist[i], XmNheight, 170); i++;
	XtSetArg(arglist[i], XmNwidth, 450); i++;
	XtSetArg(arglist[i], XmNvalue, "Large Text Box"); i++;
	XtSetArg (arglist[i], XmNscrollHorizontal, False);  i++;  
	XtSetArg (arglist[i], XmNwordWrap , True);  i++;  	
	XtSetArg (arglist[i], XmNeditMode, XmMULTI_LINE_EDIT);  i++;
	XtSetArg (arglist[i], XmNcursorPositionVisible, False); i++;
	
	n = 0;
	XtSetArg(args[n], XmNx,10); n++;
	XtSetArg(args[n], XmNy, 220); n++;
	XtSetArg (args[n], XmNrows, 18);  n++;    
	XtSetArg (args[n], XmNcolumns, 80);  n++;     
	XtSetArg (args[n], XmNeditable, False);  n++;  
/*	XtSetArg (args[n], XmNscrollHorizontal, False);  n++;  */
/*	XtSetArg (args[n], XmNwordWrap , True);  n++;  	*/
	XtSetArg (args[n], XmNcursorPositionVisible, False); n++;	
	XtSetArg (args[n], XmNeditMode, XmMULTI_LINE_EDIT); n++;   
	text_wp = XmCreateScrolledText (shell, "text_wp", args, n);    
	XtManageChild (text_wp);
	
/* Buttons */
	n=0;
	XtSetArg(args[n], XmNx, 120); n++;
	XtSetArg(args[n], XmNy, 500); n++;
	XtSetArg(args[n], XmNwidth, 100); n++;
	forward = XtCreateManagedWidget ("Forward", xmPushButtonWidgetClass, dialog, args, n);
XtAddCallback (forward, XmNactivateCallback, forw, NULL);
	
	n=0;
	XtSetArg(args[n], XmNx, 230); n++;
	XtSetArg(args[n], XmNy, 500); n++;
	XtSetArg(args[n], XmNwidth, 100); n++;
	backward = XtCreateManagedWidget ("Backward", xmPushButtonWidgetClass, dialog, args, n);
XtAddCallback (backward, XmNactivateCallback, backw, NULL);

	n=0;
	XtSetArg(args[n], XmNx, 10); n++;
	XtSetArg(args[n], XmNy, 500); n++;
	XtSetArg(args[n], XmNwidth, 100); n++;
	ok = XtCreateManagedWidget ("Ok", xmPushButtonWidgetClass, dialog, args, n);
	XtManageChild (ok);
	XtAddCallback (ok, XmNactivateCallback, read_name, NULL);

	n=0;
	XtSetArg(args[n], XmNx, 350); n++;
	XtSetArg(args[n], XmNy, 500); n++;
	XtSetArg(args[n], XmNwidth, 100); n++;
	cancel = XtCreateManagedWidget ("cancel", xmPushButtonWidgetClass, dialog, args, n);
	XtManageChild (cancel);
	XtAddCallback (cancel, XmNactivateCallback, Close, NULL);
	
	XtManageChild (dialog);
}

/*
** This is passed the prompt when called. We destroy the shell parent.
*/
void destroy_callback (Widget prompt, XtPointer client_data,
					   XtPointer call_data)
{
	XtDestroyWidget ( XtParent (prompt));
}
/* read_name() --the text field has been filled in. Get the userData
** from the dialog widget and set the PushButton's name or color.
*/
void read_name (Widget dialog, XtPointer client_data, XtPointer call_data)
{
	char       text[5000], *name;
	int        n;
	ARecord *returned;

	name = XmTextFieldGetString(search_in);

	/****************************INSERT FUNCTION HERE******************************/

	
	index=db_search(name, returned);
	if (index!=-1){
		chomp(dbase.data[index].date);
		chomp(dbase.data[index].requestor);
		chomp(dbase.data[index].email);
		chomp(dbase.data[index].priority);
		chomp(dbase.data[index].needed);
		chomp(dbase.data[index].status);
		XmTextSetString (pt1, dbase.data[index].date);
		XmTextSetString (pt2, dbase.data[index].requestor);
		XmTextSetString (pt3, dbase.data[index].email);
		XmTextSetString (pt4, dbase.data[index].priority);
		XmTextSetString (pt5, dbase.data[index].needed);
		XmTextSetString (pt6, dbase.data[index].status);
		XmTextSetString (text_wp, dbase.data[index].description); 
	}
	else
		XmTextSetString (text_wp, "Not Found!");
		/*
	printf("index = %d\n", index);
	*/
	/****************************INSERT FUNCTION HERE******************************/

	XtFree (text); /* must free text gotten from XmStringUnparse() */
	XtFree (name);
}


void my_callback (Widget w, XtPointer client_data, XtPointer call_data)
{
	XmPushButtonCallbackStruct *cbs =
		(XmPushButtonCallbackStruct *) call_data;

	if (cbs->reason == XmCR_ARM)
		printf ("%s: armed\n", XtName (w));
	else if (cbs->reason == XmCR_DISARM)
		printf ("%s: disarmed\n", XtName (w));
	else
		printf ("%s: pushed %d times\n", XtName (w), cbs->click_count);
}

void toggled (Widget widget, XtPointer client_data, XtPointer call_data)
{
	int which = (int) client_data;
	XmToggleButtonCallbackStruct *state =
		(XmToggleButtonCallbackStruct *) call_data;

	if((state->set == XmSET) && !strcmp(XtName (widget),"High"))
	{
		r1 = 1;		r2 = 0;		r3 = 0;
	}
	if((state->set == XmSET) && !strcmp(XtName (widget),"Medium"))
	{
		r1 = 0;		r2 = 1;		r3 = 0;
	}
	if((state->set == XmSET) && !strcmp(XtName (widget),"Low"))
	{
		r1 = 0;		r2 = 0;		r3 = 1;
	}
	if((state->set == XmSET) && !strcmp(XtName (widget),"Open"))
	{
		r4 = 1;		r5 = 0;		r6 = 0;
	}
	if((state->set == XmSET) && !strcmp(XtName (widget),"Awaiting"))
	{
		r4 = 0;		r5 = 1;		r6 = 0;
	}
	if((state->set == XmSET) && !strcmp(XtName (widget),"done"))
	{
		r4 = 0;		r5 = 0;		r6 = 1;
	}

	if (state->set == XmSET)
		toggle_item_set = which;
	else
		toggle_item_set = 0;
}

main(argc, argv)
int argc;
char **argv;
{
Display *display;
XFontStruct *myfont;
String fontname = "-*-courier-bold-o-*--*-140-*"; 
/*
if(!(myfont = XLoadQueryFont(display, fontname)))
printf("Error!\n");
*/

	i = 0;
	XtSetArg(arglist[i], XmNtitle, "control Panel"); i++;
	toplevel = XtAppInitialize (&context, "Panel", NULL, 0,	&argc, argv, NULL, arglist, i);

	i=0;
	manager = XtCreateManagedWidget(
		"manager", xmBulletinBoardWidgetClass,
		toplevel, arglist, i);

	i = 0;
	XtSetArg(arglist[i], XmNx,10); i++;
	XtSetArg(arglist[i], XmNy, 10); i++;
	label1 = XtCreateWidget(
		"Date:", xmLabelWidgetClass,
		manager, arglist, i);

	i=0;
	XtSetArg(arglist[i], XmNx, 100); i++;
	XtSetArg(arglist[i], XmNy, 10); i++;
	XtSetArg(arglist[i], XmNvalue, "Type text here"); i++;
	text1 = XmCreateTextField (manager, "text1", arglist, i);
	XtManageChild (label1);
	XtManageChild (text1);

	i = 0;
	XtSetArg(arglist[i], XmNx,10); i++;
	XtSetArg(arglist[i], XmNy, 40); i++;
	label2 = XtCreateWidget(
		"Requestor:", xmLabelWidgetClass,
		manager, arglist, i);

	i=0;
	XtSetArg(arglist[i], XmNx, 100); i++;
	XtSetArg(arglist[i], XmNy, 40); i++;
	XtSetArg(arglist[i], XmNvalue, "Type text here"); i++;
	text2 = XmCreateTextField (manager, "text1", arglist, i);
	XtManageChild (label2);
	XtManageChild (text2);

	i = 0;
	XtSetArg(arglist[i], XmNx,10); i++;
	XtSetArg(arglist[i], XmNy, 70); i++;
	label3 = XtCreateWidget("Email:", xmLabelWidgetClass, manager, arglist, i);

	i=0;
	XtSetArg(arglist[i], XmNx, 100); i++;
	XtSetArg(arglist[i], XmNy, 70); i++;
	XtSetArg(arglist[i], XmNvalue, "Type text here"); i++;
	text3 = XmCreateTextField (manager, "text1", arglist, i);
	XtManageChild (label3);
	XtManageChild (text3);

	i = 0;
	XtSetArg(arglist[i], XmNx,10); i++;
	XtSetArg(arglist[i], XmNy, 100); i++;
	label4 = XtCreateWidget("Priority:", xmLabelWidgetClass, manager, arglist, i);

	/*************************************************************************/
	i = 0;
	XtSetArg(arglist[i], XmNx,100); i++;
	XtSetArg(arglist[i], XmNy, 100); i++;
	radio_box = XmCreateRadioBox (manager, "radio_box", arglist, i);

	radio1 = XmCreateToggleButtonGadget (radio_box, "Low", arglist, i);
	XtAddCallback (radio1, XmNvalueChangedCallback, toggled, (XtPointer) 1);
	XtManageChild (radio1);

	radio2 = XmCreateToggleButtonGadget (radio_box, "Medium", arglist, i);
	XtAddCallback (radio2, XmNvalueChangedCallback, toggled, (XtPointer) 2);
	XtManageChild (radio2);

	radio3 = XmCreateToggleButtonGadget (radio_box, "High", arglist, i);
	XtAddCallback (radio3, XmNvalueChangedCallback, toggled, (XtPointer) 3);
	XtManageChild (radio3);

	XtManageChild (radio_box);
	/*************************************************************************/

	XtManageChild (label4);
	XtManageChild (radio1);

	i = 0;
	XtSetArg(arglist[i], XmNx,10); i++;
	XtSetArg(arglist[i], XmNy, 190); i++;
	label5 = XtCreateWidget (
		"Needed:", xmLabelWidgetClass,
		manager, arglist, i);

	i=0;
	XtSetArg(arglist[i], XmNx, 100); i++;
	XtSetArg(arglist[i], XmNy, 190); i++;
	XtSetArg(arglist[i], XmNvalue,
		"Type text here"); i++;
	text5 = XmCreateTextField (manager, "text5", arglist, i);
	XtManageChild (label5);
	XtManageChild (text5);

	i = 0;
	XtSetArg(arglist[i], XmNx,10); i++;
	XtSetArg(arglist[i], XmNy, 220); i++;
	label6 = XtCreateWidget (
		"Status:", xmLabelWidgetClass,
		manager, arglist, i);
	XtManageChild (label6);
	/*************************************************************************/
	i = 0;
	XtSetArg(arglist[i], XmNx,100); i++;
	XtSetArg(arglist[i], XmNy, 220); i++;
	radio_box2 = XmCreateRadioBox (manager, "radio_box2", arglist, i);

	radio4 = XmCreateToggleButtonGadget (radio_box2, "Open", arglist, i);
	XtAddCallback (radio4, XmNvalueChangedCallback, toggled, (XtPointer) 1);
	XtManageChild (radio4);

	radio5 = XmCreateToggleButtonGadget (radio_box2, "Awaiting", arglist, i);
	XtAddCallback (radio5, XmNvalueChangedCallback, toggled, (XtPointer) 2);
	XtManageChild (radio5);

	radio6 = XmCreateToggleButtonGadget (radio_box2, "Done", arglist, i);
	XtAddCallback (radio6, XmNvalueChangedCallback, toggled, (XtPointer) 3);
	XtManageChild (radio6);

	XtManageChild (radio_box2);
	/*************************************************************************/
	i=0;
	XtSetArg(arglist[i], XmNx, 190); i++;
	XtSetArg(arglist[i], XmNy, 250); i++;
	XtSetArg(arglist[i], XmNvalue,
		"Type text here"); i++;
	text6 = XmCreateTextField (manager, "text6", arglist, i);
	XtManageChild (text6);

	i = 0;
	XtSetArg(arglist[i], XmNx,10); i++;
	XtSetArg(arglist[i], XmNy, 310); i++;
	label7 = XtCreateWidget (
		"Description:", xmLabelWidgetClass,
		manager, arglist, i);
	XtManageChild (label7);

	i = 0;
	XtSetArg(arglist[i], XmNx, 100); i++;
	XtSetArg(arglist[i], XmNy, 310); i++;
	XtSetArg(arglist[i], XmNheight, 170); i++;
	XtSetArg(arglist[i], XmNwidth, 450); i++;
	XtSetArg(arglist[i], XmNvalue, "Large Text Box"); i++;
	XtSetArg (arglist[i], XmNscrollHorizontal, False);  i++;  
	XtSetArg (arglist[i], XmNwordWrap , True);  i++;  	
	XtSetArg (arglist[i], XmNeditMode, XmMULTI_LINE_EDIT);  i++;
	XtSetArg (arglist[i], XmNcursorPositionVisible, False); i++;
	textl = XmCreateScrolledText (manager, "textl", arglist, i);
	XtManageChild (textl);

	i=0;
	XtSetArg(arglist[i], XmNx, 10); i++;
	XtSetArg(arglist[i], XmNy, 500); i++;
	XtSetArg(arglist[i], XmNwidth, 100); i++;
	create = XtCreateManagedWidget (
		"Create", xmPushButtonWidgetClass,
		manager, arglist, i);
	XtAddCallback (create, XmNactivateCallback, add_result, NULL);

	i=0;
	XtSetArg(arglist[i], XmNx, 340); i++;
	XtSetArg(arglist[i], XmNy, 500); i++;
	XtSetArg(arglist[i], XmNwidth, 100); i++;
	search = XtCreateManagedWidget (
		"Search", xmPushButtonWidgetClass,
		manager, arglist, i);
	XtAddCallback (search, XmNactivateCallback, pushed, NULL);

	i=0;
	XtSetArg(arglist[i], XmNx, 450); i++;
	XtSetArg(arglist[i], XmNy, 500); i++;
	XtSetArg(arglist[i], XmNwidth, 100); i++;
	quit = XtCreateManagedWidget (
		"Exit", xmPushButtonWidgetClass,
		manager, arglist, i);
	XtAddCallback (quit, XmNactivateCallback, Quit, NULL);
	db_open();
	XtRealizeWidget (toplevel);
	XtAppMainLoop(context);
}


